<template>
	<view class="index">
		<view class="search-wrapper">
			<input type="text" v-model="keywords" @confirm="search" confirm-type="search" class="input"
				placeholder="输入供应商名称查询" />
			<uni-icons v-if="keywords" type="clear" @tap="keywords = '';search()" size="22" color="#898989"
				class="close"></uni-icons>
			<!-- <uni-icons type="search" class="icon" size="20" color="#acacac"></uni-icons> -->
			<image src="../static/image/search-icon.png" class="icon" mode="widthFix"></image>
			<view class="search-btn" @click="search">
				搜索
			</view>
		</view>
		<view class="tabs-wrapper">
			<v-tabs class="v-tab" v-model="current" :tabNumbers="tabNumbers" @change="changeTab" :tabs="tabList"
				:scroll="false" :bold="false" lineHeight="4rpx" lineColor="#0E932E" activeColor="#0E932E"
				color="#79838A" fontSize="30rpx"></v-tabs>
		</view>
		<view class="page-wrapper">
			<swiper class="swiper" :current="current" @change="changePage">
				<swiper-item class="swiper-item" v-for="(_swiper,i) in tabList" :key="i">
					<mescroll-item ref="mescrollItem" @getCount="getCount" :keywords="keywords" :i="i"
						:index="current"></mescroll-item>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import MescrollItem from "./mescroll-swiper-item.vue";

	export default {
		data() {
			return {
				tabList: ['供货中', '注册中', '审核中', '暂停供货', '已冻结'],
				tabNumbers: [],
				first: true,
				current: 0,
				swiperList: [],
				single: this.$helper.getDay(0, '-'),
				keywords: ''
			}
		},
		onLoad(option) {
			this.getCount()
			if (option.type) {
				this.$nextTick(() => {
					this.current = parseInt(option.type);
				})
			}
		},
		computed: {
			dateStr() {
				let str = '';
				if (this.single === this.$helper.getDay(0, '-')) {
					str += '今天 ';
				} else if (this.single === this.$helper.getDay(-1, '-')) {
					str += '昨天 ';
				} else if (this.single === this.$helper.getDay(-2, '-')) {
					str += '前天 ';
				}
				str += this.single.substring(5);
				return str;
			}
		},
		methods: {
			changePage(e) {
				this.current = e.detail.current;
			},
			changeTab() {

			},
			async getCount() {
				const data = await this.$api.get('/adm/supplier/statusCount', {}, false)
				if (data.code === 200) {
					this.tabNumbers = [data.data.in_supply, data.data.registering, data.data.under_review, data.data
						.suspend_supply, data.data.frozen
					]
				}
			},
			refresh() {
				this.getCount()
				this.$refs.mescrollItem[this.current].refresh();
			},
			search() {
				this.$refs.mescrollItem[this.current].refresh();
			},
		},
		components: {
			MescrollItem
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: hidden;

		.search-wrapper {
			background-color: #ffffff;
			margin: 3upx 0;
			padding: 10upx 20upx;
			position: relative;
			display: flex;
			align-items: center;

			.input {
				border-radius: 10upx;
				border: 2upx solid #cecece;
				height: 70upx;
				width: 100%;
				padding: 0 120upx 0 30upx;
				box-sizing: border-box;
				font-size: 32upx;
			}

			.icon {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 190upx;
				width: 26upx;
				height: 26upx;
			}

			.close {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 230upx;
			}

			.search-btn {
				width: 200upx;
				background-color: #555BFF;
				color: #ffffff;
				height: 70upx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10upx;
				margin-left: 10upx;
				font-size: 28upx;
			}
		}

		.tabs-wrapper {
			display: flex;
			align-items: center;
			background-color: #ffffff;

			.v-tab {
				flex: 1;
			}

			.date-wrapper {
				font-size: 30upx;
				margin-right: 20upx;
				color: #434343;
				display: flex;
				align-items: center;
				height: 30upx;
				border-left: 1upx solid #cecece;
				padding-left: 30upx;
				min-width: 180upx;
				text-align: center;

				.icon {
					font-weight: bold;
					margin-left: 5upx;
				}
			}
		}

		.swiper {
			height: calc(100vh - 70upx);

			.tip {
				color: #FF8D1A;
				background-color: #ffffff;
				border-radius: 20upx;
				padding: 20upx;
				font-size: 28upx;
			}

			.nodata-wrapper {
				text-align: center;
				font-size: 32upx;
				color: #666666;

				.nodata-image {
					margin-top: 300upx;
					margin-bottom: 10upx;
					width: 246upx;
				}

				.loading-image {
					margin-top: 300upx;
					margin-bottom: 10upx;
					width: 296upx;
					height: 205upx;
				}
			}
		}

	}
</style>